package com.zhang.common.web.respWrapper;


import com.zhang.constants.WebConstant;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "接口返回对象")
public class Res<T> implements Serializable {

    private static final long serialVersionUID = 1L;


    /**
     * 成功响应码
     */
    public static final int SUCCESS = WebConstant.OK_200;

    /**
     * 失败响应码
     */
    public static final int FAIL = WebConstant.INTERNAL_SERVER_ERROR_500;


    @ApiModelProperty("响应码")
    private int code;

    @ApiModelProperty("响应信息")
    private String msg;

    @ApiModelProperty("响应数据对象")
    private T result;

    public static <T> Res<T> ok(){return new Res(SUCCESS,null,null);}

    public static <T> Res<T> ok(String msg){return new Res(SUCCESS,msg,null);}

    public static <T> Res<T> ok(String msg,T res){return new Res(SUCCESS,msg,res);}

    public static <T> Res<T> ok(T res){return new Res(SUCCESS,null,res);}




    public static <T> Res<T> fail(){return new Res(FAIL,null,null);}

    public static <T> Res<T> fail(String msg){return new Res(FAIL,msg,null);}

    public static <T> Res<T> fail(String msg,T res){return new Res(FAIL,msg,res);}

    public static <T> Res<T> fail(int code,String msg,T res){return new Res(code,msg,res);}


    /**
     * 无权访问
     */
    public static <T> Res<T> noauth(){return new Res(WebConstant.Forbidden_403,"您无权访问此资源",null);}








}
